<?
/**
 * VoiceOne Settings/Extensions/Provisioning
 *
 *
 * @package voiceone
 * @subpackage  settings_extensions
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang;
  //================= POST & GET ==================
  $alert=getAlert();
  if((isset($_GET["del"]))&&(trim($_GET["del"])!="")){
    $ret=$asterisk->delProvDirectory($_GET["del"]);
    if($ret>0) $alert="<div class=\"AlertGood\">".T_("Directory has been deleted")."</div>";
    else $alert="<div class=\"AlertBad\">".T_("Directory hasn't been deleted")."</div>";
    //go to main page
    goToMainPage($alert,"./");
  }
  //================= PAGE LOGIC ==================
  $ret=$asterisk->getProvDirectory(0);
  if($err=$asterisk->getError()) die("Error: $err");
  $count=0;
  if (is_array($ret)) {
    foreach($ret as $v) {
      $id=$v["id"];
      $name=$v["name"];
      $contacts=$v["contacts"];
      if(is_array($contacts)) $num=count($contacts); else $num=0;
      //html
      $html.="<td><img src=\"".$relBasePath."public/img/directory.gif\" alt=\"Directory $id\"/> ";
      $html.="<a href=\"edit/?id=$id\">".$name." (".$num."/100)</a> ";
      $html.="<a href=\"$PHP_SELF?del=$id\" onclick=\"if (confirm('".sprintf(T_("Are you sure you want to remove directory %1\$s ?"), $name )."')) return true; else return false;\"><img src=\"$relBasePath/public/img/trash.gif\" /></a>";
      $html.="</td>\n";
      if((++$count)%2==0) $html.="</tr><tr>\n";
    }
  }

  //================ MAIN CONTENTS ================
  ob_start();
  ?>
    <?$nav="directory";include("../navigation.php");?>
    <div class="SectionHeader">
      <?=$alert?>
      <h1><?=T_("Directory")?></h1>
      <h3>
        <a href="edit/" class="admin" ><?=T_("New Directory")?></a>
      </h3>
    </div>
    <table class="todolist">
      <tr>
        <?=$html?>
      </tr>
    </table>
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
  ?>
    <div class="Sidebar">
      <?$sel="provisioning";include("../../sidebar.php");?>
      <h1><?=T_("Informations")?></h1>
    </div>
  <?
  $sidebar=ob_get_contents();
  ob_end_clean();
  //================ SETTINGS ================
  $smarty->assign("section", "extensions");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>
